home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / ZIPPED / LISTINGS / V_13_07.ZIP / DAWES.ZIP / COUNT2.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-02  |  537 b   |  26 lines

  1. //  Listing 2 - Count2 program
  2.  
  3. #include <cstring.h>
  4. #include <iomanip.h>
  5. #include <algo.h>
  6. #include <map.h>
  7.  
  8. struct long_t { long v; long_t() : v(0) {} };
  9.  
  10. typedef map< string, long_t, less<string> > map_t;
  11.  
  12. static inline int show_m( const map_t::value_type& x )
  13.   { cout << setw(7) << x.second.v << " - " << x.first << endl; }
  14.  
  15. int main() {
  16.  
  17.   map_t    ct_map;
  18.   string   str;
  19.  
  20.   while ( cin >> str ) ++ct_map[str].v;
  21.  
  22.   for_each( ct_map.begin(), ct_map.end(), ptr_fun( show_m ) );
  23.  
  24.   return EXIT_SUCCESS;
  25.   }
  26.